﻿using System;
using System.Diagnostics;

using Nextensions.Basic;

namespace Nextensions.Data
{
    public class SQL
    {
        public static OperationResult<string> Run(string FilePath, string ServerName, string UserName, string Password)
        {
            Process p = new Process();
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.FileName = "osql";
            p.StartInfo.Arguments = String.Format("-S {0} -U {1} -P {2} -i \"{3}\" -b", ServerName, UserName, Password, FilePath);
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.UseShellExecute = false;
            p.Start();
            p.WaitForExit();

            int exitCode = p.ExitCode;

            string outText = p.StandardOutput.ReadToEnd();

            return new OperationResult<string>(exitCode == 0, outText);
        }
    }
}
